# 第一题
# (1)整数和ASCII互转: 求数字68对应的ASCII码字符， 求字符F的ASCII码值
# (2)以每行8个字符打印 ASCII码表 （ascii码值100以内的）


# 第二题
# 打印99乘法表
# 1*1=1
# 1*2=2   2*2=4
# 1*3=3   2*3=6   3*3=9
# 1*4=4   2*4=8   3*4=12  4*4=16
# 1*5=5   2*5=10  3*5=15  4*5=20  5*5=25
# 1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36
# 1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49
# 1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64
# 1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81

for Second_number in range(1,10):
    for First_number in range(1,10):
        if First_number <= Second_number:
            print(First_number,"*", Second_number,"=", First_number*Second_number, end= "\t")
        if First_number == Second_number :
            print("\n")
        
            

# 第三题
# 判断一个句话（一个字符串）"Read as much as you can in English. No matter what it is, from cartoons to British literature anything counts."中是否包含下面单词列表中的任何一个单词：
# how
# are
# good
# new
# benifit
# no

import re

TEXT = "Read as much as you can in English. No matter what it is, from cartoons to British literature anything counts."

PATTERN = re.compile(r"how|are|good|new|benifit|no")

matches = re.findall(PATTERN, TEXT)

if len(matches)>0 :
    print("Yes, the text contains at least one of those words.")
else:
    print("NO ,the text doesn't contain any one of those words.")
    
# 第四题
#（1）找一个自己电脑上文件较多、文件夹层数较多的工作文件夹，分别打印列出该文件夹（及其子文件夹）中的word, ppt, 和 excel文件的绝对路径；
#（2）将上述word, ppt, 和 excel分别复制到一个独立的文件夹中。

# (1)
from pathlib import Path
from tkinter import Tk, filedialog
from os import startfile

Tk().withdraw()

MY_FOLDER = Path(filedialog.askdirectory(title = "请选择“演示用文件夹”谢谢Thanks♪(･ω･)ﾉ)"))

print("这些是“演示用文件夹”中的Word文件")
for f in MY_FOLDER.rglob("*.docx"):
    print(f)
print("这些是“演示用文件夹”中的Excel文件")
for f in MY_FOLDER.rglob("*.xlsx"):
    print(f)
print("这些是“演示用文件夹”中的PPT文件")
for f in MY_FOLDER.rglob("*.pptx"):
    print(f)

MY_PATH = Path(filedialog.askdirectory(title="Select a folder"))
parent = MY_PATH.parent 
prep = parent / "PREP" 
prep.mkdir(exist_ok=True) 
startfile(prep) 


# 第五题
# 将某一个文件夹下的所有.docx后缀的文件的文件名加上前缀&quot;DOC_&quot;进行重命名。

from pathlib import Path
from tkinter import filedialog, Tk

Tk().withdraw()

MY_FOLDER =Path(filedialog.askdirectory(title="Select 演示用文件夹"))

for f in MY_FOLDER.rglob("*.docx"):          
        new_filename = "&quot;DOC_&quot;" + "_" + f.stem + f.suffix
        new_filepath = f.with_name(new_filename)
        new_f = f.rename(new_filepath)
        print("已将原文件名", f.name, "更改为", new_f.name)
        